package com.demo.service.impl;

import com.demo.entity.UserVo;
import com.demo.entity.UsersVo;
import com.demo.service.IUserService;
import com.star.annotation.DictionaryConvert;
import com.star.annotation.RecordLog;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 用户接口实现类
 *
 * @author: star
 * @date: 2020-07-23
 */
@Service
public class UserServiceImpl implements IUserService {

    @RecordLog(content = "获取用户信息",code = "0001",operation = "新增",desc = "用户管理")
    @Override
    public UserVo getUser() {
        UserVo user = new UserVo();
        user.setId(1);
        user.setAge(new Random().nextInt(50));
        user.setName("张三");
        user.setState("1");
        return user;
    }
    @RecordLog(content = "'获取【'+user.name+'】用户'",code = "0001",operation = "新增",desc = "用户管理")
    @Override
    public UserVo getUserLog(UserVo user) {
        UserVo vo = new UserVo();
        vo.setId(1);
        vo.setAge(new Random().nextInt(50));
        vo.setName(user.getName());
        vo.setState("1");
        return vo;
    }

    @Override
    public List<UserVo> getUserList() {
        List<UserVo> list = new ArrayList<>();
        UserVo user = new UserVo();
        user.setAge(new Random().nextInt(50));
        user.setId(1);
        user.setName("张三");
        user.setState("1");
        list.add(user);
        UserVo user1 = new UserVo();
        user1.setAge(new Random().nextInt(50));
        user1.setId(2);
        user1.setName("李四");
        user1.setState("0");
        list.add(user1);
        return list;
    }

    @Override
    public UsersVo getUsers() {
        List<UserVo> list = new ArrayList<>();
        UserVo user = new UserVo();
        user.setAge(new Random().nextInt(50));
        user.setName("张三");
        user.setState("1");
        list.add(user);
        UserVo user1 = new UserVo();
        user1.setAge(new Random().nextInt(50));
        user1.setName("李四");
        user1.setState("0");
        list.add(user1);
        UserVo user2 = new UserVo();
        user2.setAge(new Random().nextInt(50));
        user2.setName("王五");
        user2.setState("3");
        UserVo user3 = new UserVo();
        user3.setAge(new Random().nextInt(50));
        user3.setName("赵六");
        user3.setState("1");
        UserVo user4 = new UserVo();
        user4.setAge(new Random().nextInt(50));
        user4.setName("刘一");
        user4.setState("0");
        UserVo user5 = new UserVo();
        user5.setAge(new Random().nextInt(50));
        user5.setName("陈二");
        user5.setState("1");
        List<UserVo> list1 = new ArrayList<>();
        list1.add(user3);
        list1.add(user4);
        List<UserVo> list2 = new ArrayList<>();
        list2.add(user5);
        List<List<UserVo>> lists = new ArrayList<>();
        lists.add(list1);
        lists.add(list2);
        UsersVo usersVo = new UsersVo();
        usersVo.setUserVos(list);
        usersVo.setUserVo(user2);
        usersVo.setUsers(lists);
        return usersVo;
    }

    @DictionaryConvert
    @Override
    public UserVo getUserConvert() {
        UserVo user = new UserVo();
        user.setAge(new Random().nextInt(50));
        user.setName("张三");
        user.setState("1");
        user.setId(1);
        return user;
    }

}
